﻿
Public Module application
    Public Event initialize()
    Public Event start()
    Public Event unload()
    Public Event [stop]()

    Private Sub [exit]()
        RaiseEvent unload()
        configLoader.stop()
        RaiseEvent stop()
        finishmain()
    End Sub

    Private Sub unhandledException(ByVal ex As Exception)
        configLoader.stop()
    End Sub

    Public Sub universeMain(ByVal defaultConfigfile As String,
                            ByVal registerComponents As void,
                            ByVal args() As String)
        debugpause()
        managedThreadPool.register()
        'threadpool.register()
        callbackManager.register()
        eventDriver.register()
        void_(registerComponents)
        resolver.global.fix()
        startmain(AddressOf unhandledException)
        Dim configFile As String = Nothing
        If args.Length() = 0 Then
            configFile = defaultConfigfile
        Else
            configFile = args(0)
        End If
        RaiseEvent initialize()
        assert(configLoader.load(configFile))
        RaiseEvent start()
        While Not consoleCancelKeyPressed()
            sleepSeconds(1)
        End While
        [exit]()
    End Sub
End Module
